package com.campus.mapper;

import com.campus.annotation.AutoFill;
import com.campus.enumeration.OperationType;
import com.campus.pojo.dto.UserPageQueryDTO;
import com.campus.pojo.entity.User;
import com.campus.pojo.vo.UserVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    /**
     * 登录
     * @param username
     * @return
     */
    @Select("select * from user where username=#{username} ")
    User getUser(String username);

    /**
     * 注册
     * @param user
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into user(name, username,password,role,status,create_time,update_time) values(#{name},#{username},#{password},#{role},#{status},#{createTime},#{updateTime})")
    void insert(User user);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id}")
    User getUserById(Long id);

    /**
     * 修改密码
     * @param userId
     * @param newPassword
     */
    @Update("update user set password=#{newPassword}, update_time = NOW() where id=#{userId}")
    void updatePassword(Long userId, String newPassword);

    Page<UserVO> pageQuery(UserPageQueryDTO userPageQueryDTO);

    @Update("update user set status = #{status}, update_time = NOW() where id= #{id}")
    void updateStatus(Long id, Integer status);

    @Update("update user set password = #{password}, update_time = NOW() where id = #{id}")
    void resetPassword(Long id, String password);
}
